cmake_minimum_required(VERSION 3.5)

project(gdus LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)

# XML file name
set(XML_FILE example.xml)
# generated file name
set(XML_GEN_FILE ExampleGdbusGenerated)

# check if the length of one of the above two lists is same as one of the other one
list(LENGTH XML_FILE XML_FILE_LEN)
list(LENGTH XML_GEN_FILE XML_GEN_FILE_LEN)
#message(${XML_FILE_LEN})
#message(${XML_GEN_FILE_LEN})
math(EXPR XML_FILE_LEN "${XML_FILE_LEN}-1")
math(EXPR XML_GEN_FILE_LEN "${XML_GEN_FILE_LEN}-1")

IF (${XML_FILE_LEN} EQUAL ${XML_GEN_FILE_LEN})
    message("start generate files from XML")
    # generate files from XML
    FOREACH(INDEX RANGE 0 ${XML_FILE_LEN})
        list(GET XML_FILE ${INDEX} XML)
        list(GET XML_GEN_FILE ${INDEX} NAME_TMP)
#        execute_process(COMMAND gdbus-codegen --interface-prefix xxxx --c-namespace aisdk --generate-c-code ${PROJECT_BINARY_DIR}/${NAME_TMP} ${PROJECT_SOURCE_DIR}/${XML})
        execute_process(COMMAND gdbus-codegen --interface-prefix org.openkylin.aisdk. --c-namespace Aisdk --generate-c-code ${PROJECT_SOURCE_DIR}/${NAME_TMP} ${PROJECT_SOURCE_DIR}/${XML})
    ENDFOREACH(INDEX)
ELSE (${XML_FILE_LEN} EQUAL ${XML_GEN_FILE_LEN})
    message(FATAL_ERROR "The length (${XML_FILE_LEN}) of xml files list does not equal to the length(${XML_GEN_FILE_LEN}) of the generated files name list")
ENDIF(${XML_FILE_LEN} EQUAL ${XML_GEN_FILE_LEN})